

#import "YYSTabBarController.h"
#import "YYSNavigationController.h"
#import "YYSHomePageController.h"
#import "YYSCenterController.h"
#import "FMWriteVideoController.h"
#import "ViewController.h"
@implementation YYSTabBarController

+(void)initialize
{
    //利用富文本属性设置文字颜色
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *Attributes = [NSMutableDictionary dictionary];
    Attributes[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [item setTitleTextAttributes:Attributes forState:UIControlStateNormal];
    
    NSMutableDictionary *Attributes2 = [NSMutableDictionary dictionary];
    Attributes2[NSForegroundColorAttributeName] = YYSGlobalColor;
    [item setTitleTextAttributes:Attributes2 forState:UIControlStateSelected];
    
    //设置tabBar的背景图片
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_bar_new_bg"]];

}


-(void)viewDidLoad
{
    [super viewDidLoad];
    //1设置子控制器
    [self setUpChildController];
    [self.viewControllers enumerateObjectsUsingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
        
        switch (idx) {
            case 0:{
                
                
            } break;
            case 1:{
                obj.tabBarItem.enabled=NO;
                obj.tabBarItem.title=@"";
                
                
            } break;
            case 2:{
               
                
            } break;
          
            
                
            default:
                break;
        }
    }];
}

-(void)setUpChildController
{
    
    YYSHomePageController *home = [[YYSHomePageController alloc] init];
    [self setChild:home image:@"huikuang" selectedImage:@"lvse-1" title:@"首页"];
    ViewController *home2 = [[ViewController alloc] init];
    [self setChild:home2 image:@"" selectedImage:@"" title:@""];
    YYSCenterController *search = [[YYSCenterController alloc] init];
    [self setChild:search image:@"weidianji" selectedImage:@"lvse" title:@"个人中心"];
    
//    self.customSelectViews  = [[NSMutableArray alloc] init];
//
//    for (UIView *UITabBarButton in self.tabBar.subviews) {
//        
//        if ([@"UITabBarButton" isEqualToString:NSStringFromClass([UITabBarButton class])]) {
//            
//            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(UITabBarButton.frame.origin.x+UITabBarButton.frame.size.width/2-5, UITabBarButton.frame.origin.y+UITabBarButton.frame.size.height-5, 10, 5)];
//            imageView.image = [UIImage imageNamed:@"main_point"];
//            [self.tabBar addSubview:imageView];
//            [self.customSelectViews addObject:imageView];
//            
//        }
//    }
    CGFloat width = 60;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0 , 0, width+10, width+10)];
    view.layer.cornerRadius = (width+10)/2;
    view.layer.masksToBounds = YES;
    view.backgroundColor = YYSRGBColor(235, 235, 235);
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-width/2 , -25, width, width)];
    
    button.layer.cornerRadius = width/2;
    button.layer.masksToBounds = YES;
    view.center = button.center;
    [button setBackgroundColor:YYSGlobalColor];
    button.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [button setImage:[UIImage imageNamed:@"shangchuan"] forState:UIControlStateNormal];
    [self.tabBar addSubview:view];
    [self.tabBar addSubview:button];
    [self.tabBar bringSubviewToFront:button];
    [button addTarget:self action:@selector(selectImagePicker) forControlEvents:UIControlEventTouchUpInside];

    
}
- (void)selectImagePicker
{
    FMWriteVideoController *writeVC = [[FMWriteVideoController alloc] init];
    UINavigationController *NAV = [[UINavigationController alloc] initWithRootViewController:writeVC];
    [self presentViewController:NAV animated:YES completion:nil];
}
/**
 *  添加子控制器
 *
 *  @param vc            字控制器类型
 *  @param image         TabBarItem的image
 *  @param selectedImage TabBarItem选中的image
 *  @param title         TabBarItem的标题
 */
-(void)setChild:(UIViewController *)vc image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title
{
//    vc.view.backgroundColor = [UIColor orangeColor];
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    vc.tabBarItem.title = title;
    [self addChildViewController:[[YYSNavigationController alloc] initWithRootViewController:vc]];
}
@end
